package com.google.adwords.samples.disapproved.auth;

import com.google.adwords.samples.disapproved.Config;

import java.rmi.Remote;
import java.rmi.RemoteException;

/**
 * General interface for authentication
 * @author alecmgo@gmail.com (Alec Go)
 *
 */
public class Login {
  private static LoginInterface loginInterface = null;

  /**
   * Sets the headers for an interface
   * @param service
   * @param clientEmail
   * @return stub with the headers set
   * @throws RemoteException
   */

  public static Remote setHeaders(Remote service, String clientEmail,
      Config config) throws RemoteException {

    if (loginInterface == null) {
      String loginClass = config.getLoginClass();
      try {
        loginInterface =
            (LoginInterface) Class.forName(loginClass).newInstance();
      } catch (InstantiationException e) {
        throw new Error(e);
      } catch (IllegalAccessException e) {
        throw new Error(e);
      } catch (ClassNotFoundException e) {
        throw new Error(e);
      }
    }
    return loginInterface.setHeaders(service, clientEmail, config);
  }
}
